import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class Talker(Node):
    def __init__(self):
        super().__init__('talker_node_py')
        self.counter=1
        self.get_logger().info('发布发创建py')
        self.publisher_=self.create_publisher(String,'chatter',10)
        # 秒为单位
        self.timerer_=self.create_timer(1.0,self.on_timer)
    pass
    def on_timer(self):
        message=String()
        message.data='hello world py'+str(self.counter)
        self.publisher_.publish(message)
        self.counter+=1
        self.get_logger().info(f'发布py 发送 {message.data}')
        pass

def main():
    rclpy.init()
    rclpy.spin(Talker())
    rclpy.shutdown()


if __name__ == '__main__':
    main()
